﻿
/// <reference path="../../Common/Scripts/jquery.min.js" />
/// <reference path="~/Content/Common/Widget/kindeditor/kindeditor-min.js" />
/// <reference path="../../Common/Widget/jquery-easyui/jquery.easyui.min.js" />

/*公共属于*/
var logoutPostUrl = "/admin/login/LoginOut";  //登入验证提交地址
var loginPageUrl = "/admin/login/index";      //登入页面地址
var GetCultureComboBoxJsonUrl = "/admin/System/GetCultureComboBoxJson"; //获取语言下拉列表数据地址
var ChangePasswordPageUrl = "/admin/user/ChangePassword"; //修改密码页面
var ChangePasswordPostUrl = "/admin/user/ChangePassword"; //修改密码Post提交页面
var SettingSitePageUrl = "/Admin/Setting/Site";
var SettingContactUsPageUrl = "/Admin/Setting/ContactUs";
var SettingAboutPageUrl = "/Admin/Setting/About";
var SettingSalesNetworkPageUrl = "/Admin/Setting/SalesNetwork";
var SettingCommanyPageUrl = "/Admin/Setting/Commany";
var SettingVideoPageUrl = "/Admin/Setting/Video";
var SettingJsonUrl = "/Admin/Setting/SettingJson";
var SettingUploadJson = "/Admin/Setting/UploadSettingJson";
var SettingFileManagerJson = "/Admin/Setting/FileManagerSettingJson";
var CurrentCulture = "zh-cn";
var CultureComboboxJsonData = [{ "id": "zh-cn", "text": "中文", "selected": false }, { "id": "en-us", "text": "English", "selected": false }];

/*Jquery easyui 扩展*/
var msgShow = function (title, msgString, msgType, fn) {
    var content = "<div style=\"padding: 5px 34px\">" + msgString + "</div>";
    $.messager.alert(title, content, msgType, fn);
};
/*显示AJAX表单提交返回信息*/
var AjaxMessage = function (data, fn) {
    if (data.state) {
        $.messager.alert('提示', data.message, "info", fn);
    } else {
        $.messager.alert('提示', data.message, "error", fn);
    }
};
/* Admin页面初始化 */
/*后台登出*/
var LoginOut = function () {
    $.messager.confirm('系统提示', '您确定要退出本次登录吗?', function (r) {
        if (r) {
            $.ajax({
                url: logoutPostUrl,
                type: 'Post',
                dataType: 'json',
                timeout: 1000,
                success: function (data) {
                    if (data.state)
                        location.href = loginPageUrl;
                    else {
                        msgShow("登出提示", data.message, data.state ? "info" : "error", function () {
                            if (data.state)
                                location.href = loginPageUrl;
                        });
                    }

                }
            });
        }
    });
};
/*Tabs 添加TABS方法定义*/

var EditTableCellElement = function (id, rowData) {
    return '<span style="color:red" class="jqeasyui-datagrid-edit-' + id + '"  value=' + rowData.Id + '>修改</span>';
};
var ImageTableCellElement = function (id, rowDate) {

};
/*Table 方法定义*/
/*创建 table 元素*/
var CreatTableElement = function (id, tilte) {
    var tableHtml = "<table id=\"" + id + "\" style=\"height:100%\" title=\"" + '' + "\" iconcls=\"icon-edit\"><\/table>";
    return tableHtml;
};
/*定义 table 列添加方法*/
var TableAddRecord = function (table, url) {

};
/*定义 table 列删除方法*/
var TableDeleteRecord = function (table, url) {
    var rows = $(table).datagrid('getSelections');
    if (!rows || rows.length == 0) {
        $.messager.alert('提示', '请选择要删除的数据');
        return;
    }
    var parm;
    $.each(rows, function (i, n) {
        if (i == 0) {
            parm = "id=" + n.Id;
        } else {
            parm += "&id=" + n.Id;
        }
    });
    $.messager.confirm('提示', '是否删除这些数据?', function (r) {
        if (!r) {
            return;
        }
        $.ajax({
            type: "POST",
            url: url,
            data: parm,
            success: function (msg) {
                if (msg.state) {
                    $.messager.alert('提示', '删除成功！', "info", function () {
                        $(table).datagrid("reload");
                    });
                }
            },
            error: function () {
                $.messager.alert('错误', '删除失败！', "error");
            }
        });
    });
};
/*Table 方法定义*/
/*panel 控制面板定义*/
/*创建一个控制面板*/
var CreatePanelElement = function (id, title) {
    var panelElement = '<div id="' + id + '"  title="' + '' + '" style="height:auto" ></div>  ';
    return panelElement;
};
/*将表单转化为JSON对象*/
$.fn.serializeObject = function () {
    var o = {};
    var a = this.serializeArray();
    $.each(a, function () {
        if (o[this.name]) {
            if (!o[this.name].push) {
                o[this.name] = [o[this.name]];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return o;
};
/*Table 默认属性定义*/
var TableOptionDefault = $.extend($.fn.datagrid.defaults, {
    width: 'auto',
    height: '500',
    nowrap: false,
    striped: true,
    fit: true,
    remoteSort: true,
    collapsible: true,
    fitColumns: true,
    sortName: 'Sort',
    sortOrder: 'asc',
    idField: 'Id',
    pagination: true,
    onLoadSuccess: function () {

    },
    toolbar: [{
        text: '添加',
        iconCls: 'icon-add',
        handler: function () {

        }
    }, '-', {
        text: '删除',
        iconCls: 'icon-remove',
        handler: function () {
        }
    }],
    onBeforeLoad: function () {
        $(this).datagrid('rejectChanges');
    },
    onClickRow: function (rowIndex) {
        $(this).datagrid("unselectRow", rowIndex);
    },
    onSelect: function (rowIndex, rowData) {

    }
});
/*控制面板默认属性*/
var PanelDefaultOption = $.extend($.fn.panel.defaults, { border: true, cache: false, height: 'auto', loadingMessage: "正在载入..." });
/*window 弹窗定义*/
var WindowsDefaultOption = $.extend($.fn.window.defaults, { loadingMessage: "正在载入...", cache: false });

/*validatebox 表单验证*/
$.extend($.fn.validatebox.defaults.rules, {
    /*必须和某个字段相等*/
    equalTo: {
        validator: function (value, param) {
            return $(param[0]).val() == value;
        },
        message: '字段不匹配'
    }
});

var Url = {
    Advertisement: { CreateControl: '', EditControl: '', IndexConrol: '' },
    Article: {},
    Candidates: { CreateControl: '', EditControl: '', IndexConrol: '' },
    Category: {},
    Link: { CreateControl: '', EditControl: '', IndexConrol: '' },
    Login: {},
    Order: { CreateControl: '', EditControl: '', IndexConrol: '' },
    Product: {},
    Permission: {},
    Recruitment: {},
    Setting: {},
    Shared: {},
    User: {}
};
